// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}

const int N = 2e3+50;
#define int long long
vector<int> a, p;
vector<vector<int>> dp;
vector<pair<int, int>> dat;
int n;

inline void update(int &a, int b) {
    a = max(a, b);
}

signed main() {
    // code
    scanf("%lld", &n);
    a = vector<int>(n);
    for (int i=0; i<n; ++i) {
    scanf("%lld", &a[i]);
        dat.emplace_back(a[i], i);
    }

    sort(dat.rbegin(), dat.rend());

        
    dp = vector<vector<int>>(n+1, vector<int>(n+1, 0));
    for (int i=0; i<n; ++i) {
        dbg(dat[i].first, dat[i].second);
        for (int j=0; j<=i; ++j) {
            dbg(i, j, dat[i].second, n, i, j, dat[i].second - (n - (i-j) - 1));
            update(dp[i+1][j], dp[i][j] + abs(dat[i].second - (n-(i-j)-1)) * dat[i].first);
            update(dp[i+1][j+1], dp[i][j] + abs(dat[i].second - j) * dat[i].first);
        }
    }

    dbg(dp[2][1]);

    printf("%lld\n", *max_element(dp[n].begin(), dp[n].end()));
    
    return 0;
}